﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Webadmin_Modules_Yahoo_ListEdit : bzAdminUCBase
{
    public string _Act = "";
    public string _ID = "";
    public DataTable _dt = new DataTable();
    public DataRow dr = null;
    private bzYahoo bz = new bzYahoo();
    TextBox txtNameFull = new TextBox();
    override protected void loadAction()
    {
        _Act = Request.QueryString["Act"] == null ? "" : Request.QueryString["Act"];
        _ID = Request.QueryString["ID"] == null ? "-1" : Request.QueryString["ID"];
        if (!IsPostBack)
        {
            switch (_Act)
            {
                case "Edit": this.loadEdit(); break;
                case "Add": this.resetData(); break;
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.initSiteLang(bzSiteOption.Group.Administrator, bzSiteOption.None, "Yahoo");
    }
    private void loadEdit()
    {
        this.Navigator = this.AdminLang["MenuYahoo"].ToString() + this.AdminLang["GeneralArrow"].ToString() + this.AdminLang["MenuYahooList"].ToString() + this.AdminLang["GeneralArrow"].ToString() + this.AdminLang["Edit"].ToString();
        this.btnUpdate.Text = this.AdminLang["Edit"].ToString();
        DataTable _dtYahoo = new bzYahoo().getRecord(_ID, "-1");
        this.txtNameFull.Text = _dtYahoo.Rows[0]["NameFull"].ToString();
        this.txtDepartmentVN.Text = _dtYahoo.Rows[0]["DepartmentVN"].ToString();
        this.txtDepartmentEN.Text = _dtYahoo.Rows[0]["DepartmentEN"].ToString();
        this.txtNickName.Text = _dtYahoo.Rows[0]["NickName"].ToString();
        this.rdForward_1.Enabled = false;
        this.rdForward_0.Checked = true;
        this.rdEnabled_1.Checked = Convert.ToInt16(_dtYahoo.Rows[0]["Enabled"]) <= 0 ? false : true;
        this.rdEnabled_0.Checked = !this.rdEnabled_1.Checked;
       
     }
    private void resetData()
    {
        this.Navigator = this.AdminLang["MenuYahoo"].ToString() + this.AdminLang["GeneralArrow"].ToString() + this.AdminLang["MenuYahooList"].ToString() + this.AdminLang["GeneralArrow"].ToString() + this.AdminLang["AddNew"].ToString();
        this.txtNameFull.Text = "";
        this.txtDepartmentVN.Text = "";
        this.txtDepartmentEN.Text = "";
        this.txtNickName.Text = "";
        this.rdForward_0.Checked = false;
        this.rdForward_1.Checked = !this.rdForward_0.Checked;
        this.btnUpdate.Text = this.AdminLang["AddNew"].ToString();
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        switch (_Act)
        {
            case "Edit": this.doEdit(); break;
            case "Add": this.doAdd(); break;
        }
    }
    private void doEdit()
    {
        if (this.AllowEdit)
        {
            this.editImage();
        }
        else { Response.Redirect(bzStringClass.AlertPermission); }
    }
    private void doAdd()
    {
        if (this.AllowAdd)
        {
            this.insertImage();
        }
        else { Response.Redirect(bzStringClass.AlertPermission); }
    }  

    //-----------------------------------------------------------------
    private void editImage()
    {
        if (bz.updateRecord(_ID,this.txtNameFull.Text, this.txtDepartmentVN.Text, this.txtDepartmentEN.Text, this.txtNickName.Text, this.rdEnabled_0.Checked ? "0" : "1") > 0)
        {
            Response.Write(bzStringClass.addStringAlert(this.AdminLang["Success"]));
            Response.Write(bzStringClass.redirectClient(Session["Page"].ToString()));
        }

    }
    private void insertImage()
    {
        if (bz.insertRecord(this.txtNameFull.Text, this.txtDepartmentVN.Text, this.txtDepartmentEN.Text, this.txtNickName.Text,this.rdEnabled_0.Checked ? "0" : "1") > 0)
        {
            if (this.rdForward_0.Checked)
            {
                Response.Write(bzStringClass.addStringAlert(this.AdminLang["Success"]));
                Response.Write(bzStringClass.redirectClient(Session["Page"].ToString()));
            }
            else this.resetData();
        }
    }    
}
